package com.axjy.yycg.web;


import com.axjy.yycg.service.PermissionService;
import com.axjy.yycg.service.vo.TreeNode;
import com.axjy.yycg.util.Log;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sys/permission")
public class PermissionHandler {

    private String msg;
    @Resource
    private PermissionService permissionService;

    @GetMapping("/search4Tree")
    public List<TreeNode> search4Tree(Integer roleId){
        List<TreeNode> list=permissionService.search4Tree(roleId);
        return list;
    }

    @PostMapping("/grant4Role")
    public String grant4Role(Integer roleId,Integer[] mids){
        try {
            permissionService.grant4Role(roleId,mids);
            msg="角色授权成功";
        }catch (RuntimeException ex){
            msg="角色授权失败";
            Log.logger.error(msg,ex);
        }
        return msg;
    }


}
